<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
class Master extends Common
{
    public function index(){
        $master=Db::name("Masters")->select();
        $this->assign("master",$master);
        return $this->fetch();
    }
    public function form(){
        return $this->fetch();
    }
    public function add(){
        $data=[
            'm_name'=>input('m_name'),
            'm_tel'=>input('m_tel'),
            'm_intro'=>input('m_intro'),
            'm_address'=>input('m_address'),
            'm_hit'=>input('m_hit')

        ];
        if (Db::name('Masters')->insert($data)){
            $this->success('添加成功','Master/index');
        }else $this->error('添加失败');
        return $this->fetch();
    }

    public function mod($id){
        $master=Db::name("Masters")->find($id);
        $this->assign("master",$master);
        return $this->fetch();
    }
    public function edit(){

        $data=[
            'm_id'=>input('m_id'),
            'm_name'=>input('m_name'),
            'm_tel'=>input('m_tel'),
            'm_intro'=>input('m_intro'),
            'm_address'=>input('m_address'),
            'm_hit'=>input('m_hit')
        ];
        if (Db::name('Masters')->update($data)){
            $this->success('修改成功','Master/index');
        }else $this->error('修改失败');
        return $this->fetch();
    }



    public function delete($id){
        if (Db::name("Masters")->delete($id)){
            $this->success('删除成功');
        }else $this->error('删除失败');
    }


    public function search(){
        $key=input('key');
        // dump($key);exit;
        if(!$key){
            $this->success('无搜索内容','Master/index');
        }else{
            $master=Db::table('Masters')->where('m_name','like','%'.$key.'%')->select();
            $this->assign("master",$master);
            // dump($activity);exit;
            return $this->fetch('index');

        }

        // dump($sql);
    }
    public function jiekou(){

        $rs=Db::name('Masters')->select();
        return json($rs);
    }

}